package org.metasketch.simulator.transformation.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.metasketch.demo.model.TransactionKind;

public class ChildParentMap {

	Map<TransactionKind, List<TransactionKind>> parents = new HashMap<TransactionKind, List<TransactionKind>>();

	public void registerRelation(TransactionKind child, TransactionKind parent) {
		List<TransactionKind> ps = parents.get(child);
		if (ps == null) {
			ps = new ArrayList<TransactionKind>();
			parents.put(child, ps);
		}

		if (!ps.contains(parent))
			ps.add(parent);

	}

	public boolean isParent(TransactionKind child, TransactionKind parent) {
		List<TransactionKind> ps = parents.get(child);
		if (ps == null)
			return false;

		if (ps.contains(parent))
			return true;

		return false;
	}

//	public boolean isChild(TransactionKind child, TransactionKind parent) {
//		return !isParent(child, parent);
//	}

}
